Skip to content

Hotfix/2.13.1#707

Merged
bastiandoetsch merged 2 commits intomasterfrom
hotfix/2.13.1
May 26, 2025
Merged

Hotfix/2.13.1#707
bastiandoetsch merged 2 commits intomasterfrom
hotfix/2.13.1

Conversation

@bastiandoetsch
Copy link
Collaborator

Description

Provide description of this PR and changes, if linked Jira ticket doesn't cover it in full.

Checklist

  • Tests added and all succeed
  • Linted
  • CHANGELOG.md updated
  • README.md updated, if user-facing

Screenshots / GIFs

Visuals that may help the reviewer. Please add screenshots for any UI change. GIFs are most welcome!

bastiandoetsch and others added 2 commits May 23, 2025 15:47
* fix(lsp): improve process handling in LanguageServerWrapper [IDE-1228]

- Renamed lsIsAlive() to processIsAlive() for better clarity
- Added proper process alive checks before destroying
- Added tests to verify initialization and shutdown behavior
- Ensures the process is only terminated when it exists, preventing exceptions

* chore: add windsurfrules file [IDE-1228]

Added windsurfrules file to define standards for AI assistant interactions with the codebase. This includes guidelines for testing, security scanning, issue fixing, and commit message formatting.

* chore: remove unneeded imports

* docs: updated CHANGELOG.md

* test(lsp): improve LanguageServerWrapper shutdown test [IDE-1228]

- Improved the shutdown test to properly verify workspace folder clearing and process termination
- Removed ineffective test that didn't test actual implementation behavior
- Added test to verify process lifecycle management during shutdown

(cherry picked from commit ad2b147)
…DE-1235] (#706)

* fix: improve path and URI conversion for cross-platform compatibility

This commit enhances the path and URI conversion functionality to ensure
reliable file path handling across different operating systems.
Specifically improves Windows path handling with proper URI encoding/decoding
and adds comprehensive tests to verify the bidirectional conversion between
paths and URIs works correctly on both POSIX and Windows systems.

* fix: more test cases and use ASCII strings

* fix: toLanguageServerURL

* fix: toLanguageServerURL tests

* fix: improve language server initialization and URI handling [IDE-1203]

- Increase language server initialization timeout from 20L to 2000L
- Add proper error handling when adding content roots
- Run content root addition asynchronously to prevent UI freezes
- Improve error logging with more descriptive messages
- Add user notification when language server fails to initialize
- Replace size > 0 check with isNotEmpty() for better readability
- Fix code formatting and parameter organization

* fix: tests in ReferenceChooserDialogTest.kt

* fix: error handling in fromUriToPath

Co-authored-by: windsurf-bot[bot] <189301087+windsurf-bot[bot]@users.noreply.github.com>

* fix: windsurf suggestion

* fix: test setup for ReferenceChooserDialogTest.kt

* chore: revert timeout

* docs: CHANGELOG.md

* fix: normalize path before using it to persist folderConfig

* fix: Improve folder config path normalization and add tests [IDE-1203]

Ensures that FolderConfigSettings consistently handles folder paths
by normalizing and absolutizing them. The 'folderPath' property
of FolderConfig objects managed by FolderConfigSettings will
now always reflect this normalized, absolute path.

This resolves an issue where the stored folderPath in FolderConfig
objects did not always represent the fully normalized and absolute
path used as the key in the settings map, leading to potential
inconsistencies and failing tests for path normalization.

Key changes include:
- Added FolderConfigSettingsTest.kt with comprehensive unit tests
  for path normalization, covering various scenarios including
  paths with '.', '..', and equivalent path representations.
- Converted tests to JUnit 4 syntax as per project standards.
- Updated FolderConfigSettings:
  - 'addFolderConfig' now stores a copy of the FolderConfig with
    its 'folderPath' correctly normalized and absolutized.
  - 'createEmpty' now directly instantiates FolderConfig with the
    normalized path, improving clarity and efficiency.
- Fixed a compile error in ReferenceChooserDialogTest.kt by
  refactoring a direct private field access to use a public method.

* chore: update initialization messaging in summary [IDE-1235]

* refactor: ReferenceChooserDialogTest.kt setup

* refactor: add tests, normalize more paths

* refactor: ensure file separator suffix in folder configs

* fix: tests

---------

Co-authored-by: Abdelrahman Shawki Hassan <shawki.hassan@snyk.io>
(cherry picked from commit 9ba9809)
@bastiandoetsch bastiandoetsch marked this pull request as ready for review May 23, 2025 14:16
@bastiandoetsch bastiandoetsch requested a review from a team as a code owner May 23, 2025 14:16
Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other comments (3)
  • src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt (488-494) The same URI to path conversion is performed twice for each workspace folder. Consider extracting this conversion to avoid duplication:
                .filter { folder ->
                    val folderPath = folder.uri.fromUriToPath().toString()
                    folderConfigsRefreshed[folderPath] == true
                }.map { folder ->
                    val folderPath = folder.uri.fromUriToPath().toString()
                    service<FolderConfigSettings>().getFolderConfig(folderPath)
    
  • src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt (60-66) While adding error handling is good, the current implementation only logs the error without any recovery strategy. Consider adding fallback behavior or notifying the user when content roots cannot be added, as this might affect scanning functionality.
  • src/main/kotlin/snyk/common/lsp/settings/FolderConfigSettings.kt (30-37) The normalizePath function has a redundant variable assignment. You can simplify this by returning the expression directly:
    private fun normalizePath(folderPath: String): String {
        return Paths.get(folderPath)
            .normalize()
            .toAbsolutePath()
            .toString()
            .suffixIfNot(File.separator)
    }
    

Comment on lines +430 to +433
fun String.fromUriToPath(): Path {
val filePath = Paths.get(URI.create(this))
return filePath.normalize()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fromUriToPath() method doesn't handle potential exceptions from URI.create(). If an invalid URI string is passed, this will throw an IllegalArgumentException. Consider adding exception handling to gracefully handle malformed URIs.

Comment on lines +447 to 449
fun String.fromPathToUriString(): String {
return Paths.get(this).normalize().toUri().toASCIIString()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fromPathToUriString() method should include exception handling for cases where the path contains characters that can't be properly encoded in a URI or when the path format is invalid.

logger.warn(e)
process.destroy()
logger.error("Initialization of Snyk Language Server failed", e)
if (processIsAlive()) process.destroyForcibly()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The process destruction should check if the process is initialized before attempting to destroy it forcibly. Consider using if (::process.isInitialized && process.isAlive) process.destroyForcibly() to avoid potential exceptions.

@bastiandoetsch bastiandoetsch merged commit e52d952 into master May 26, 2025
11 checks passed
@bastiandoetsch bastiandoetsch deleted the hotfix/2.13.1 branch May 26, 2025 06:29
@bastiandoetsch bastiandoetsch restored the hotfix/2.13.1 branch May 26, 2025 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant